package com.lgkj.ui.shop;

import android.view.View;
import android.widget.ListView;

import com.google.gson.Gson;
import com.lgkj.R;
import com.lgkj.adapter.CommentAdapter;
import com.lgkj.bean.meitao.CommentBean;
import com.lgkj.ui.BaseActivity;
import com.lgkj.utils.CommonConstant;
import com.lgkj.utils.HttpUtils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/8/20 0020.
 */

public class CommentListActivity extends BaseActivity {
    @BindView(R.id.lv_item)
    ListView lvItem;
    @BindView(R.id.srl_refresh)
    SmartRefreshLayout srlRefresh;
    private CommentAdapter adapter;
    private CommentBean commentBean;
    private String status = "0";

    @Override
    public int getLayoutId() {
        return R.layout.activity_comment_list;
    }

    @Override
    public void initView() {
        setTitle("商品评价");
        adapter = new CommentAdapter(CommentListActivity.this);
        lvItem.setAdapter(adapter);
    }

    @Override
    public void initData() {
        getOrderList("-1");
    }

    @OnClick({R.id.rb_tab2, R.id.rb_tab3, R.id.rb_tab4, R.id.rb_tab5})
    public void onClick(View view) {
        //order_status（发货状态 0未发货 1已发货 2已收货 3已评价） *
        // 0 未支付 1已支付
        switch (view.getId()) {
            case R.id.rb_tab2:
                status = "-1";
                break;
            case R.id.rb_tab3:
                status = "10";
                break;
            case R.id.rb_tab4:
                status = "5";
                break;
            case R.id.rb_tab5:
                status = "0";
                break;
        }
        getOrderList(status);
    }

    private void getOrderList(String status) {
        showDiaLog("正在获取数据");
        Map<String, String> map = new HashMap<>();
        map.put("access_token", getToken());
        map.put("goods_id", "230");
        if (!status.equals("-1"))
            map.put("rate_score", status);
        HttpUtils.postHttp(map, CommonConstant.getRateListByGoods, new HttpUtils.HttpCallBack() {
            @Override
            public void successHttp(JSONObject jsonObject, int id) {
                dismissDiaLog();
                if (jsonObject.optInt("code") == 0) {
                    Gson mGson = new Gson();
                    if (jsonObject.optJSONObject("data") != null) {
                        commentBean = mGson.fromJson(String.valueOf(jsonObject), CommentBean.class);
                        if (commentBean.getData().getData() != null) {
                            adapter.setData(commentBean.getData().getData());
                            adapter.notifyDataSetChanged();
                        }
                    }
                } else {
                    toastLong(jsonObject.optString("msg"), 0);
                }
            }

            @Override
            public void errorHttp(String msg) {
                dismissDiaLog();
            }
        });
    }

}
